import 'package:flutter/material.dart';
//import 'package:flutterxc/dao/travel_dao.dart';
import 'package:flutterxc/dao/travel_tab_dao.dart';
//import 'package:flutterxc/module/travel_tab_model.dart';
import 'package:flutterxc/module/travel_tab_model2.dart';
import 'package:flutterxc/pages/travel_tab_page.dart';

class FenxiangPage extends StatefulWidget {
  FenxiangPage({Key key}) : super(key: key);

  @override
  _FenxiangPageState createState() => _FenxiangPageState();
}

class _FenxiangPageState extends State<FenxiangPage> with TickerProviderStateMixin{
  TabController _controller;
  List<TravelTab> tabs = [];
  TravelTabModel2 _travelTabModel;
  @override
  void initState() {
    _controller = TabController(vsync: this,length: 0);
    // TODO: implement initState
    super.initState();
    TravelTabDao.fetch().then((res){
      _controller = TabController(vsync: this,length: res.district.groups.length);
      print(res);
      setState(() {
        tabs = res.district.groups;
        _travelTabModel = res;
      });
    }).catchError((err){
      print(err);
    });
  }
  @override
  void dispose() {
    _controller.dispose();
    // TODO: implement dispose
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    final EdgeInsets padding = MediaQuery.of(context).padding;

    return Scaffold(
      body: Column(
        children: <Widget>[
          SafeArea(
//            color: Colors.white,
//            padding: EdgeInsets.only(top: padding.top),
            child: TabBar(
              controller: _controller,
//              是否可滑动切换
              isScrollable: true,
//              title颜色
              labelColor: Colors.black87,
//              title padding
              labelPadding: EdgeInsets.fromLTRB(20, 0, 10, 5),
//              底部指示器
              indicator: UnderlineTabIndicator(
                borderSide: BorderSide(color: Color(0xff2fcfbb),width: 3),
//                insets: EdgeInsets.only(bottom: 10)
              ),
              tabs: tabs.map((TravelTab item){
                return Tab(text: item.name,);
              }).toList(),
            ),
          ),
          Flexible(
            child: TabBarView(
              controller: _controller,
              children: tabs.map((item){
                return TravelTabPage(travelUrl: _travelTabModel?.url ?? '',groupChannelCode: item.code,);
              }).toList(),
            ),
          )
        ],
      ),
    );
  }
}